package org.zyj.io.example.case4;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleStateEvent;

public class MyHeatBeatHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if (evt instanceof IdleStateEvent idleStateEvent) {
            switch (idleStateEvent.state()) {
                case READER_IDLE -> readIdle();
                case WRITER_IDLE -> writeIdle();
                case ALL_IDLE -> allIdle();
            }
        }
    }

    private void allIdle() {
        System.out.println("读写空闲");
    }

    private void writeIdle() {
        System.out.println("写空闲");
    }

    private void readIdle() {
        System.out.println("读空闲");
    }
}
